package com.jelica.videoteka.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;


import com.jelica.videoteka.beans.Korisnik;
import com.jelica.videoteka.interfaces.IznajmljivanjeI;
import com.jelica.videoteka.interfaces.KorisnikI;
import com.jelica.videoteka.interfaces.PomocniKorisnikI;
import com.jelica.videoteka.service.KorisniksI;

public class UnosKorisnika {

	@Property
	@Persist
	private KorisnikI korisnik;

	@Inject
	private KorisniksI korisniks;

	@SetupRender
	public void createObject() {
		korisnik = new Korisnik();
		korisnik.setIznajmljivanjeI(new LinkedList<IznajmljivanjeI>());
	}

	void onSuccess() {
		korisniks.save(korisnik);
	}
	@SessionState
	private PomocniKorisnikI pomocniKorisnikI;

	private boolean pomocniKorisnikIExists;
	
	public PomocniKorisnikI getKorisnikI() {
		return pomocniKorisnikI;
	}
	
	Object onActivate() {
		if (!pomocniKorisnikIExists) return Login.class;
		return null;
	}
}
